package com.jthinker.service.impl;

import com.jthinker.dao.RoleDao;
import com.jthinker.service.RoleService;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 */
@Service
public class RoleServiceImpl implements RoleService
{
    @Resource
    private RoleDao roleDao;

    @Override
    public Map<String, Object> findOne(Long roleId)
    {
        return roleDao.findOne(roleId);
    }

    @Override
    public Set<String> findRoles(Long... roleIds)
    {
        Set<String> roles = new HashSet<String>();
        for (Long roleId : roleIds)
        {
            Map<String, Object> role = findOne(roleId);
            if (role != null)
            {
                roles.add(MapUtils.getString(role, "role"));
            }
        }
        return roles;
    }

    @Override
    public Set<String> findPermissions(Long... roleIds)
    {
        Set<String> ids = new HashSet<String>();
        for (Long roleId : roleIds)
        {
            Map<String, Object> role = findOne(roleId);
            //            ids.addAll(role.getArrayString("resource_ids"));
        }
        return ids;
    }
}
